package com.xuexi.mr.fof;

import java.io.IOException;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.util.StringUtils;

public class FriendsMapper extends Mapper<Text, Text, FoF, IntWritable>{

	protected void map(Text key, Text value,
			Context context)
			throws IOException, InterruptedException {
		String user =key.toString();
		String[]  friends =StringUtils.split(value.toString(), '\t');
		for (int i = 0; i < friends.length; i++) {
			String one = friends[i];
			context.write(new FoF(user, one), new IntWritable(2));
			for (int j = i+1; j < friends.length; j++) {
				String other = friends[j];
				context.write(new FoF(one, other), new IntWritable(1));
			}
		}
	}
}
